package com.luo.mapper;

import com.luo.pojo.Class;
import com.luo.pojo.Gender;
import com.luo.pojo.Student;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

import java.util.List;

/**
 * <p>
 * 学生信息表 Mapper 接口
 * </p>
 *
 * @author luo
 * @since 2025-06-22
 */
@Mapper
public interface StudentMapper extends BaseMapper<Student> {


    /**
     * 计算平均年龄
     * @return 平均年龄
     */
    @Select("select avg(age) from student")
    Integer AvgAge();

    /**
     * 查询各班级人数
     * @return 各班级人数
     */
    @Select("select class_id , count(*) as TheClassSize from student group by class_id")
    @Results({
        @Result(property = "classId", column = "class_id"),
        @Result(property = "theClassSize", column = "TheClassSize")
    })
    List<Class> CheckTheClassSize();

    /**
     * 各性别人数
     * @return 各性别人数
     */
    @Select("select gender , count(*) as TheSexSize from student group by gender")
    @Results({
        @Result(property = "gender", column = "gender"),
        @Result(property = "theSexSize", column = "TheSexSize")
    })
    List<Gender> CountBySex();
}
